package com.damieoa.damieoa.controller;

import com.damieoa.damieoa.pojo.Staff;
import com.damieoa.damieoa.pojo.Station;
import com.damieoa.damieoa.service.StationService;
import com.damieoa.damieoa.vo.PageUtils;
import com.damieoa.damieoa.vo.SysResult;
import com.github.pagehelper.ISelect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@Transactional
@RequestMapping("/station")
public class StationController {

    @Autowired
    private StationService stationService;

    //增加岗位
    @PostMapping("/add")
    public SysResult addStation(@RequestBody Station station){
        stationService.addStation(station);
        return SysResult.success();
    }

    //查询岗位
    @GetMapping("/query")
    public SysResult queryStation(Station station){
        return SysResult.success(PageUtils.startPage().doSelectPageInfo(new ISelect() {
            @Override
            public void doSelect() {
                stationService.queryStation(station);
            }
        }));
    }

    //删除岗位
    @DeleteMapping("/delete")
    public SysResult deleteStation(Station station){
        stationService.deleteStation(station);
        return SysResult.success();
    }

    //根据岗位id获取岗位信息
    @GetMapping("/queryById")
    public SysResult getStationById(Station station){
        return SysResult.success(stationService.getStationById(station));
    }

    //修改岗位信息
    @PutMapping("/update")
    public SysResult updateStation(@RequestBody Station station){
        stationService.updateStation(station);
        return SysResult.success();
    }

    //查询岗位员工
    @GetMapping("/queryUser")
    public SysResult queryStationStaff(Station station){
        return SysResult.success(PageUtils.startPage().doSelectPageInfo(new ISelect() {
            @Override
            public void doSelect() {
                stationService.queryStationStaff(station);
            }
        }));
    }

    //查询删除岗位员工
    @DeleteMapping("/deleteUser")
    public SysResult deleteStationStaff(Staff staff){
        stationService.deleteStationStaff(staff);
        return SysResult.success();
    }

}
